<?php
include 'connectdb.php';
include 'base.php';
include 'requireLogin.php';
if (isset($_POST['ok_button'])){
        $varDate = $_POST['a_date'];
        $varDate1= $_POST['i_date'];
        $skSQL =" SELECT bill.*,product.* from bill,product where bill.date <'" .$varDate. "'and bill.date >'" .$varDate1."' and product.code = bill.product_code and bill.status='1'";
        $result=mysql_query($skSQL);
        if(mysql_num_rows($result)> 0)
        {   
                echo"<b>Nhân viên bán hàng từ ngày $varDate1 đến ngày $varDate: </b>";
                echo"<table border='1'>
                <tr>
                <th>Tên nhân viên</th>
                <th>Mã nhân viên</th>
                <th>Thông tin</th>
                <th>Doanh thu</th>
                <th>Lãi suất</th>
                </tr>";
                while($row = mysql_fetch_array($result))
                {
                        $sSQL="SELECT * FROM seller where seller.code='".$row['seller_code']."'";
                        $subresult=mysql_query($sSQL);
                        if(mysql_num_rows($subresult)>0){
                                while($row1 = mysql_fetch_array($subresult)){
                                        if($row['seller_code']==$row1['code']){
                                                $temp = $row['quantity']*$row['sale_price']-$row['quantity']*$row['sale_price']*$row['discount']/100;
                                                $temp1= $row['quantity']*$row['import_price'];
                                                $temp2= $temp-$temp1;
                                                echo"<tr>";
                                                echo"<td>" . $row1['name']."</td>";
                                                echo"<td>" . $row1['code']."</td>";
                                                echo"<td>" . $row1['infor']."</td>";
                                                echo"<td>" . number_format($temp,3)." VND"."</td>";
                                                echo"<td>" . number_format($temp2,3)." VND"."</td>";
                                                echo "</tr>";
                                        }
                                }
                        }
                }
                 echo"</table>";
        }
}
?>
<script language="JavaScript" type="text/javascript">

    $(document).ready(function () {
        $( "#i_date" ).datepicker();
        $( "#a_date" ).datepicker();
    });
    
</script>

<form method="post" action="">
        <div class="form_settings">                    
            <p> <span>Thống kê từ </span><input type="text" name="i_date" id = "i_date"  /></p>
            <p> <span>Đến trước ngày </span><input type="text" name="a_date" id = "a_date" value ="<?php echo date("Y-m-d");?>" /></p>
            <span>&nbsp;</span><input class="submit" type="submit" id = "submit" name="ok_button" value="OK" />
        </div>
    </form>
<?php include 'footer.php';?>
